package com.example.mvpdemo.simple5;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.example.mvpdemo.R;
import com.example.mvpdemo.simple5.base.BaseActivity;

public class Simple5Activity extends BaseActivity<WeatherView_5, WeatherPresenter_5> implements WeatherView_5 {

    /**
     * simple5
     * mvp
     * 优化：
     * Activity抽象 + 泛型设计
     */
    private TextView mWeatherContent;
    private EditText mCitynameEdit;
    String cityname = "北京";

    private static final String TAG = "Simple5Activity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple5);

        mWeatherContent = findViewById(R.id.weather_content_tv);
        mCitynameEdit = findViewById(R.id.cityname_edit);
        mCitynameEdit.setText(cityname);
    }

    public void getWeatherData(View view) {

        cityname = mCitynameEdit.getText().toString().trim();
        if (getPresenter() != null) {
            getPresenter().weeather(cityname);
        }else{
            Log.d(TAG, "getWeatherData: is null");
        }


    }

    @Override
    public void onWeatherGetSuccess(String result) {
        mWeatherContent.setText("查询结果：\n" + result);
        Log.d(TAG, "onWeatherGetSuccess: ");
    }

    @Override
    public void onWeatherGetFail(String result) {
        mWeatherContent.setText("查询结果：\n" + result);
        Log.d(TAG, "onWeatherGetFail: ");
    }


    @Override
    public WeatherPresenter_5 createPresenter() {

        Log.d(TAG, "createPresenter: ");
        return new WeatherPresenter_5();
    }

    @Override
    public WeatherView_5 createView() {
        Log.d(TAG, "createView: ");
        return this;
    }

}